package Generic;

import java.util.*;

/**
 * @author 王艺锡
 * @version 1.0
 */
@SuppressWarnings({"all"})
public class Exercise {
    public static void main(String[] args) {
        System.out.println("=========HashSet========");
        HashSet<Student> students = new HashSet<Student>();
        students.add(new Student("jack",23));
        students.add(new Student("tom",25));
        students.add(new Student("lihua",32));

        for (Student student :students) {
            System.out.println(student);
        }

        System.out.println("===迭代器===");
        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()) {
            Student student =  iterator.next();
            System.out.println(student);
        }

        System.out.println();
        System.out.println("=========HashMap========");
        HashMap<String, Student> hashMap = new HashMap<String,Student>();
        hashMap.put("yx",new Student("yx",22));
        hashMap.put("ly",new Student("ly",22));
        hashMap.put("luren",new Student("luren",19));

        Set<String> keySet = hashMap.keySet();
        for (String key :keySet) {
            System.out.println(hashMap.get(key));
        }


        System.out.println("===迭代器===");
        Set<Map.Entry<String, Student>> entries = hashMap.entrySet();
        Iterator<Map.Entry<String, Student>> iterator1 = entries.iterator();

        while (iterator1.hasNext()) {
            Map.Entry<String, Student> next = iterator1.next();
            System.out.println(next.getValue());                  }


    }
}
class Student{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}